package com;

import bean.SensorReading;
import org.apache.flink.api.java.tuple.Tuple;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.List;

/**
 * @Description: TODO QQ1667847363
 * @author: xiao kun tai
 * @date:2021/11/3 10:08
 */
public class Test {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        String inputPath = "src/main/resources/group.txt";

        DataStream<String> inputStream = env.readTextFile(inputPath);

        /****
         * 转换为SensorReading类型
         */

/*        DataStream<SensorReading> dataStream =inputStream.map(new MapFunction<String, SensorReading>() {
            @Override
            public SensorReading map(String s) throws Exception {
                String[] fields =s.split(",");
                return new SensorReading(fields[0],new Long(fields[1]),new Double(fields[2]));
            }
        });*/

        /**
         *
         */
//        DataStream<String> dataStream = inputStream.map(line->{
//            String[] fields = line.split(",");
//            return new SensorReading(fields[0],new Long(fields[1]),new Double(fields[2]));
//        });
        /***
         * 分组
         */
//
//        KeyedStream<String, Tuple> keyedStream = inputStream.keyBy("id");
//
//        KeyedStream<SensorReading, String> keyedStream1 = dataStream.keyBy(data -> data.getId());
//        KeyedStream<SensorReading, String> keyedStream2 = dataStream.keyBy(SensorReading::getId);
//
//
//
////        DataStream<SensorReading> resultStream = keyedStream.max("temperature");
////
////
////        DataStream<SensorReading> resultStream1 = keyedStream.maxBy("temperature");
//
//        resultStream.print("max");
        env.execute("");


    }
}
